<?php
	include("/../../data.php");
	session_start();
	if(($_SESSION['db_is_logged_in'] == false) || ($_SESSION['profile'] != 'admin'))
		header("location:index.php");
	
	$pass = "";	
	$connect=mysql_connect($DatabaseServer,$DatabaseUsername,$DatabasePassword) or die("can't connect this database");
	mysql_select_db($DatabaseName,$connect);
    $sql="select * from staff where username='".$_SESSION['username'] ."'";
    $query=mysql_query($sql);
	
	if(mysql_num_rows($query)==0) {
			header("location:index.php");     
    } 
	else{
		$row=mysql_fetch_array($query);         
		$pass = $row["password"];
	}
	
	if(isset($_COOKIE['InputUsername'])){
		if( ($_SESSION['db_is_logged_in'] == true) && ( $_COOKIE["InputUsername"]!=$pass))
		{
			//header("location:index.php");
		}
	}
	
	if( ($_SESSION['db_is_logged_in'] == true)&&( $_SESSION['password']!=$pass))
	{
		header("location:index.php");
	}
?>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Import Excel to MySql</title>
</head>
<body>



<?php
	function format_ten($hoten)
	{
		$hoten = trim($hoten);
		$hotens = explode(" ",$hoten);
		$n = count($hotens);
		$ten = '';
		if($n == 1)
		{
			$ten = $hotens[0];
		}
		
		if($n > 1)
		{
			$ten = $hotens[$n-1];
		}
		return $ten;
	}
	
	function format_ho($hoten)
	{
		$hoten = trim($hoten);
		$hotens = explode(" ",$hoten);
		$n = count($hotens);
		$ho = '';
		if($n>=2)
		{
			$ho = $hotens[0];
		}
		return $ho;
	}
	
	function format_tenlot($hoten)
	{
		$hoten = trim($hoten);
		$hotens = explode(" ",$hoten);
		$n = count($hotens);
		$tenlot = '';
		
		if($n >= 2)
		{
			for($i=1; $i < $n-1; ++$i)
			{
					$tenlot = $tenlot .$hotens[$i] .' ';
			}
			$tenlot = trim($tenlot);
		}
		
		return $tenlot;
	}
		
	function format_ngaysinh($MicrosoftTimestamp)
	{
		$MicrosoftTimestamp = trim($MicrosoftTimestamp);
		$temp = explode("/",$MicrosoftTimestamp);
		if(count($temp) == 0){
			//Chuyển Microsoft Timestamp to UnixTimestamp
			$UnixTimestamp = ($MicrosoftTimestamp - 25569) * 86400;
			$datetimeStr = date('Y-m-d H:i:s', $UnixTimestamp);
			
			$temp = explode("/",$datetimeStr);
			$ngay = $temp[0];
			$thang = $temp[1];
			$nam = $temp[2];
			$ngaythangnam = new Datetime($thang .'/' .$ngay .'/' .$nam);
			
			return $ngaythangnam;
		}
		else{
			$ngay = $temp[0];
			$thang = $temp[1];
			$nam = $temp[2];
			$ngaythangnam = new Datetime($thang .'/' .$ngay .'/' .$nam);
			
			//echo date_format($ngaythangnam, 'd-m-Y');
			return $ngaythangnam;
		}
	}
	
	function convert_to_string($MicrosoftTimestamp)
	{
		$MicrosoftTimestamp = trim($MicrosoftTimestamp);
		$temp = explode("/",$MicrosoftTimestamp);
		
		//echo count($temp);
		
		
		if(count($temp) <= 1){
			//Chuyển Microsoft Timestamp to UnixTimestamp
			$UnixTimestamp = ($MicrosoftTimestamp - 25569) * 86400;
			$datetimeStr = date('d/m/Y', $UnixTimestamp);
			//echo $datetimeStr;
			return $datetimeStr;
		}
		else{
			return $MicrosoftTimestamp;
		}
	}
	
	function format_ngay($thoigian)
	{
		$thoigian = convert_to_string($thoigian);
		$temp = explode("/",$thoigian);
		return $temp[0];
	}
	
	function format_thang($thoigian)
	{
		$thoigian = convert_to_string($thoigian);
		$temp = explode("/",$thoigian);
		return $temp[1];
	}
	
	function format_nam($thoigian)
	{
		$thoigian = convert_to_string($thoigian);
		$temp = explode("/",$thoigian);
		return $temp[2];
	}
	
	function format_string($string)
	{ 
		$string = str_replace("'", "" , $string);
		return $string;
	}
	
	function divide_string($string, $number)
	{
		$string = trim($string);
		$strings = explode('/',$string);
		$n = count($strings);
		$string = '';
		
		if($n >= $number)
		{
			$string = $strings[$number - 1];
		}
		
		return $string;
	}
	
	function query_sql($sql)
	{
		$result = mysql_query($sql);

		if (!$result) {
			echo "Could not successfully run query ($sql) from DB: " . mysql_error();
			exit;
		}

		if (mysql_num_rows($result) == 0) {
			echo "No rows found, nothing to print so am exiting";
			exit;
		}
		
		
		return $result;
	}
	
	
	function insertDatabase($cmdText_Students, $cmdText_Address, $cmdText_Students_Join_Address, $cmdText_Student_Enrollment, $cmtText_Staff, $cmdText_Students_Join_Users, $cmdText_Staff_School_RelationShip){
		/*
		mysql_query("SET AUTOCOMMIT=0");
		mysql_query("START TRANSACTION");

		$t1 = mysql_query($cmdText_Students);
		$t2 = mysql_query($cmdText_Address);
		$t3 = mysql_query($cmdText_Students_Join_Address);
		$t4 = mysql_query($cmdText_Student_Enrollment);
		$t5 = mysql_query($cmtText_Staff);
		$t6 = mysql_query($cmdText_Students_Join_Users);
		$t7 = mysql_query($cmdText_Staff_School_RelationShip);

		if ($t1 and $t2 and $t3 and $t4 and $t5 and $t6 and $t7) 
		{
			mysql_query("COMMIT");
			echo '<p>' ."INSERT SUCCED" .'</p>';	
		} 
		else 
		{        
			mysql_query("ROLLBACK");
			echo '<p>' ."INSERT FAILSE" .'</p>';	
		}
		*/

		
		if (!mysql_query($cmdText_Students))
		{
			die('Error: ' . mysql_error($conn));
		}
		else
		{
			echo '<p>' ."1 record students added" .'</p>';	
		}
		
		if (!mysql_query($cmdText_Address))
		{
			die('Error: ' . mysql_error($conn));
		}
		else
		{
			echo '<p>' ."1 record address added" .'</p>';	
		}
		
		if (!mysql_query($cmdText_Students_Join_Address))
		{
			die('Error: ' . mysql_error($conn));
		}
		else
		{
			echo '<p>' ."1 record students_join_address added" .'</p>';	
		}
		
		if (!mysql_query($cmdText_Student_Enrollment))
		{
			die('Error: ' . mysql_error($conn));
		}
		else
		{
			echo '<p>' ."1 record student_enrollment added" .'</p>';	
		}
		
		if (!mysql_query($cmtText_Staff))
		{
			die('Error: ' . mysql_error($conn));
		}
		else
		{
			echo '<p>' ."1 record staff added" .'</p>';	
		}	
              
		if (!mysql_query($cmdText_Students_Join_Users))
		{
			die('Error: ' . mysql_error($conn));
		}
		else
		{
			echo '<p>' ."1 record students_join_users added" .'</p>';	
		}
					
		if (!mysql_query($cmdText_Staff_School_RelationShip))
		{
			die('Error: ' . mysql_error($conn));
		}
		else
		{
			echo '<p>' ."1 record staff_school_relationship added" .'</p>';	
		}		
		
		
	}
	
	function insertOneDatabase($cmtText){
		if (!mysql_query($cmtText))
		{
			die('Error: ' . mysql_error($conn));
		}
		else
		{
			echo '<p>' ."1 record added" .'</p>';	
		}		
	}
	
	//Function Main
	if ($_FILES["file"]["error"] > 0)
	{
		echo "Error: " . $_FILES["file"]["error"] . "<br>";
	}
	else
		{
			/** Access Database **/
			$conn = mysql_connect($DatabaseServer,$DatabaseUsername,$DatabasePassword);
			mysql_set_charset('utf8',$conn);
			if (!$conn) {
				echo "Unable to connect to DB: " . mysql_error();
				exit;
			}

			if (!mysql_select_db($DatabaseName)) {
				echo "Unable to select opensisdata: " . mysql_error();
				exit;
			}
		
		

			
			echo "Upload: " . $_FILES["file"]["name"] . "<br>";
			echo "Type: " . $_FILES["file"]["type"] . "<br>";
			echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
			echo "Stored in: " . $_FILES["file"]["tmp_name"];
			$location = $_FILES["file"]["tmp_name"];
	
			error_reporting(E_ALL);
			ini_set('display_errors', TRUE);
			ini_set('display_startup_errors', TRUE);
			date_default_timezone_set('Europe/London');

			define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

			/*
			//Import Library
			require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
			require_once '/../Classes/PHPExcel/IOFactory.php';
			$objPHPExcel = PHPExcel_IOFactory::load($location);
*/
			//Import Library
			require_once '../Classes/PHPExcel.php';
			require_once '../Classes/PHPExcel/IOFactory.php';
			$objPHPExcel = PHPExcel_IOFactory::load($location);
			
			//$worksheet = $objPHPExcel->getWorksheetIterator()->getCellCollection[0];
			$i = 0; //SHEET = 0;
			foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
			if($i == 0)
			{
				$worksheetTitle     = $worksheet->getTitle();
				$highestRow         = $worksheet->getHighestRow(); // e.g. 10
				$highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
				$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
				$nrColumns = ord($highestColumn) - 64;
				
				
				//echo "<br>The worksheet ".$worksheetTitle." has ";
				//echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
				//echo ' and ' . $highestRow . ' row.';
				//echo '<br>Data: <table border="1"><tr>';
				
				for ($row = 2; $row <= $highestRow; ++ $row) {
				//for ($row = 2; $row <=2; ++ $row) {	
				
					/**for ($col = 0; $col < $highestColumnIndex; ++ $col) {
						$cell = $worksheet->getCellByColumnAndRow($col, $row);
						$val = $cell->getValue();
						$dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
						echo '<p>' . $col  . '.  ' . $val .'</p>';	
					}**/
					$countcell = 0;
					
					for ($col = 0; $col < $highestColumnIndex; ++ $col) {
						$cell = $worksheet->getCellByColumnAndRow($col, $row);
						if($cell == "")
						{
							++ $countcell; 
						}
						
					}
					
					//Kiểm tra cột dữ liệu excel
					if($countcell <= 10){
					
					
					echo '<p>' ."INSERT STUDENT " .($row-1) .'</p>';	
					
					$stt = 					$worksheet->getCellByColumnAndRow(0, $row);
					$lopHCMUS= 				$worksheet->getCellByColumnAndRow(1, $row);
					$lopOther= 				$worksheet->getCellByColumnAndRow(2, $row);
					$idHCMUS= 				$worksheet->getCellByColumnAndRow(3, $row);
					$idOther=				$worksheet->getCellByColumnAndRow(4, $row);
					$tinhtrang=  			$worksheet->getCellByColumnAndRow(5, $row);
					$hotensinhvien= 		$worksheet->getCellByColumnAndRow(6, $row); 
					$ngaysinh= 				$worksheet->getCellByColumnAndRow(7, $row); 
					$gioitinh= 				$worksheet->getCellByColumnAndRow(8, $row); 
					$cmnd= 					$worksheet->getCellByColumnAndRow(9, $row); 
					$dienthoaisinhvien=	 	$worksheet->getCellByColumnAndRow(10, $row);
					$emailsinhvien= 		$worksheet->getCellByColumnAndRow(11, $row);
					$diachihokhau= 			$worksheet->getCellByColumnAndRow(12, $row);
					$diachiguithu= 			$worksheet->getCellByColumnAndRow(13, $row);
					$tinh= 					$worksheet->getCellByColumnAndRow(14, $row);
					$hotenphuhuynh= 		$worksheet->getCellByColumnAndRow(15, $row);
					$moiquanhe= 			$worksheet->getCellByColumnAndRow(16, $row);
					$dienthoaiphuhuynh= 	$worksheet->getCellByColumnAndRow(17, $row);
					$emailphuhuynh= 		$worksheet->getCellByColumnAndRow(18, $row);
					$ghichu= 				$worksheet->getCellByColumnAndRow(19, $row);
					
					
					/**____________________ Xử lý họ tên sinh viên ____________________**/
					//echo '<p>' .'Xử lý họ tên sinh viên' .'</p>';
					//echo '<p>' . $hotensinhvien .'</p>';
					$hotensinhvien = mb_convert_case($hotensinhvien, MB_CASE_TITLE, "UTF-8");
					$hosinhvien= format_ho($hotensinhvien) .' ' .format_tenlot($hotensinhvien);
					//$tenlotsinhvien= format_tenlot($hotensinhvien);
					$tensinhvien= format_ten($hotensinhvien);
					//echo '<p>' . $hosinhvien .'</p>';
					//echo '<p>' . $tenlotsinhvien .'</p>';
					//echo '<p>' . $tensinhvien .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Xử lý điện thoại sinh viên ____________________**/
					//echo '<p>' .'Xử lý điện thoại sinh viên' .'</p>';
					//echo '<p>' . $dienthoaisinhvien .'</p>';
					$dienthoaisinhvien1 = divide_string($dienthoaisinhvien, 1);
					$dienthoaisinhvien2 = divide_string($dienthoaisinhvien, 2);
					$dienthoaisinhvien3 = divide_string($dienthoaisinhvien, 3);
					//echo '<p>' . $dienthoaisinhvien1 .'</p>';
					//echo '<p>' . $dienthoaisinhvien2 .'</p>';
					//echo '<p>' . $dienthoaisinhvien3 .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Xử lý ngày sinh ____________________**/
					//echo '<p>' .'Xử lý ngày sinh' .'</p>';
					//echo '<p>' . $dataType .'</p>';
					$ngay = format_ngay($ngaysinh);
					$thang = format_thang($ngaysinh);
					$nam = format_nam($ngaysinh);
					$ngaythangnam = new Datetime($thang .'/' .$ngay .'/' .$nam);
					//echo '<p>' . date_format($ngaythangnam, 'Y-m-d') .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Xử lý giới tính ____________________**/
					//echo '<p>' .'Xử lý giới tính' .'</p>';
					//echo '<p>' . $dataType .'</p>';
					if($gioitinh == 'Nam')
					{
						$gioitinh = 'Male';
					}
					else
					{
						$gioitinh = 'Female';
					}
					//echo '<p>' . $gioitinh .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Xử lý họ tên phụ huynh ____________________**/
					//echo '<p>' .'Xử lý họ tên phụ huynh' .'</p>';
					//echo '<p>' . $hotenphuhuynh .'</p>';
					$hotenphuhuynh1 = divide_string($hotenphuhuynh, 1);
					$hotenphuhuynh2 = divide_string($hotenphuhuynh, 2);
					$hotenphuhuynh3 = divide_string($hotenphuhuynh, 3);
					//echo '<p>' . $hotenphuhuynh1 .'</p>';
					//echo '<p>' . $hotenphuhuynh2 .'</p>';
					
					//Phụ huynh 1
					$hotenphuhuynh1 = mb_convert_case($hotenphuhuynh1, MB_CASE_TITLE, "UTF-8");
					$hophuhuynh1= format_ho($hotenphuhuynh1) .' ' .format_tenlot($hotenphuhuynh1);
					$tenphuhuynh1= format_ten($hotenphuhuynh1);
					
					//Phụ huynh 2
					$hotenphuhuynh2 = mb_convert_case($hotenphuhuynh2, MB_CASE_TITLE, "UTF-8");
					$hophuhuynh2= format_ho($hotenphuhuynh2) .' ' .format_tenlot($hotenphuhuynh2);
					$tenphuhuynh2= format_ten($hotenphuhuynh2);
					//echo '<p>' . $hophuhuynh1 .'</p>';
					//echo '<p>' . $tenphuhuynh1 .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Xử lý quan hệ sinh viên ____________________**/
					//echo '<p>' .'Xử lý quan hệ sinh viên' .'</p>';
					//echo '<p>' . $moiquanhe .'</p>';
					$moiquanhe1 = divide_string($moiquanhe, 1);
					$moiquanhe2 = divide_string($moiquanhe, 2);
					$moiquanhe3 = divide_string($moiquanhe, 3);
					//echo '<p>' . $moiquanhe1 .'</p>';
					//echo '<p>' . $moiquanhe2 .'</p>';
					//echo '<p>' . $moiquanhe3 .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Xử lý điện thoại phu huynh ____________________**/
					//echo '<p>' .'Xử lý điện thoại phụ huynh' .'</p>';
					//echo '<p>' . $dienthoaiphuhuynh .'</p>';
					$dienthoaiphuhuynh1 = divide_string($dienthoaiphuhuynh, 1);
					$dienthoaiphuhuynh2 = divide_string($dienthoaiphuhuynh, 2);
					$dienthoaiphuhuynh3 = divide_string($dienthoaiphuhuynh, 3);
					//echo '<p>' . $dienthoaiphuhuynh1 .'</p>';
					//echo '<p>' . $dienthoaiphuhuynh2 .'</p>';
					//echo '<p>' . $dienthoaiphuhuynh3 .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Xử lý địa chỉ ____________________**/
					//echo '<p>' .'Xử lý địa chỉ' .'</p>';
					$diachihokhau = format_string($diachihokhau);
					$diachiguithu = format_string($diachiguithu);
					//echo '<p>' . $diachihokhau .'</p>';
					//echo '<p>' . $diachiguithu .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Xử lý mật khẩu ____________________**/
					//echo '<p>' .'Xử lý mật khẩu' .'</p>';
					$matkhausinhvien = md5($idHCMUS);
					//echo '<p>' .$matkhausinhvien .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/********************************************************************************************************/
					/********************************************************************************************************/
					/********************************************************************************************************/
					
					
					/**____________________ Get student_id ____________________**/
					$sql = "SELECT * FROM students ORDER BY student_id DESC limit 1";
					$result = query_sql($sql);
					
					$student_id = 0;
					while ($data = mysql_fetch_assoc($result)) {
						$student_id = $data["student_id"];
					}
					mysql_free_result($result);
					
					//echo '<p>' .'student_id: ' .$student_id .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Get address_id ____________________**/
					$sql = "SELECT * FROM address ORDER BY address_id DESC limit 1";
					$result = query_sql($sql);
					
					$address_id = 0;
					while ($data = mysql_fetch_assoc($result)) {
						$address_id = $data["address_id"];
					}
					mysql_free_result($result);
					
					//echo '<p>' .'address_id: ' .$address_id .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Get _join_address_id ____________________**/
					$sql = "SELECT * FROM students_join_address ORDER BY id DESC limit 1";
					$result = query_sql($sql);
					
					$join_address_id = 0;
					while ($data = mysql_fetch_assoc($result)) {
						$join_address_id = $data["id"];
					}
					mysql_free_result($result);
					
					//echo '<p>' .'join_address_id: ' .$join_address_id .'</p>';
					/**____________________==========End==========____________________**/
					
					
					/**____________________ Get staff_id ____________________**/
					$sql = "SELECT * FROM staff ORDER BY staff_id DESC limit 1";
					$result = query_sql($sql);
					
					$staff_id = 0;
					while ($data = mysql_fetch_assoc($result)) {
						$staff_id = $data["staff_id"];
					}
					mysql_free_result($result);
					
					//echo '<p>' .'staff_id: ' .$staff_id .'</p>';
					/**____________________==========End==========____________________**/
					
					/**____________________ Get student_enrollment_id ____________________**/
					$sql = "SELECT * FROM student_enrollment ORDER BY id DESC limit 1";
					$result = query_sql($sql);
					
					$student_enrollment_id = 0;
					while ($data = mysql_fetch_assoc($result)) {
						$student_enrollment_id = $data["id"];
					}
					mysql_free_result($result);
					
					//echo '<p>' .'student_enrollment_id: ' .$student_enrollment_id .'</p>';
					/**____________________==========End==========____________________**/
					
					/********************************************************************************************************/
					/********************************************************************************************************/
					/********************************************************************************************************/
					
					
					$_student_id = $student_id + 1;
					$_address_id = 1 + $address_id;
					$_join_address_id = 1 + $join_address_id;
					$_staff_id = 1 + $staff_id;
					$_student_enrollment_id = 1 + $student_enrollment_id;
					
					$_next_school = "";
					$_prim_student_relation = "Father";

					
					$_school_id = $_POST["schoolid"];                                                                 //SCHOOL
					$_calendar_id = $_POST["calendarid"];
					$_grade_id = 1;
					$_syear = "2013";
					$_start_date = $_POST["_start_date"];
					
								
			
					//////////////////////////////////////////
					
				
					/** get id by lopOther 
						get id by lopHCMUS **/
					$_lopOther_id = "";
					$_lopHCMUS_id = "";
					$_status_id = "";
					
					$result_lopOther_id = query_sql("SELECT * 
													FROM class_other
													WHERE title ='" .$lopOther ."'" ." limit 1");
											
					while ($data = mysql_fetch_assoc($result_lopOther_id)) {		
						$_lopOther_id = $data["id"];
					}										
					
					
					/*
					$result_lopHCMUS_id	= query_sql("SELECT * 
													FROM class_hcmus
													WHERE title ='" .$lopHCMUS ."'" ." limit 1");					
											
					while ($data = mysql_fetch_assoc($result_lopHCMUS_id)) {
						$_lopHCMUS_id = $data["id"];
					}
					*/
					
					$cmdText_Students = "INSERT INTO `students`(`student_id`, `class_hcmus_id`, `last_name`, `first_name`,  `username`, `password`, `gender`, `birthdate`, `hcmus_id`, `email`, `phone`, `other_id`, `class_other_id`, `status_id`, `phone2`, `phone3`) VALUES (" .$_student_id .", '"  .$_lopHCMUS_id ."', '" .$hosinhvien ."', '" .$tensinhvien ."', '" .$idHCMUS ."', '" .$matkhausinhvien ."', '" .$gioitinh ."', '" .date_format($ngaythangnam, 'Y-m-d') ."', '" .$idHCMUS ."', '" .$emailsinhvien ."', '" .$dienthoaisinhvien1 ."', '" .$idOther ."', '" .$_lopOther_id ."', '" .$_status_id ."', '" .$dienthoaisinhvien2 ."', '" .$dienthoaisinhvien3 ."')";
					//echo '<p>' .$cmdText_Students .'</p>';

					$cmdText_Address = "INSERT INTO `address` (`address_id`, `city`, `street`, `address`, `student_id`, `prim_student_relation`, `pri_first_name`, `pri_last_name`, `home_phone`, `work_phone`, `mobile_phone`, `email`,  `sec_student_relation`, `sec_first_name`, `sec_last_name`, `sec_home_phone`, `sec_work_phone`, `sec_mobile_phone`, `sec_email`) VALUES (" .$_address_id .", '"  .$tinh ."', '" .$diachihokhau ."', '" .$diachiguithu ."', '" .$_student_id ."', '" .$moiquanhe1 ."', '" .$hophuhuynh1 ."', '" .$tenphuhuynh1 ."', '" .$dienthoaiphuhuynh1 ."', '" .$dienthoaiphuhuynh2 ."', '" .$dienthoaiphuhuynh3 ."', '" .$emailphuhuynh ."', '" .$moiquanhe2 ."', '" .$hophuhuynh2 ."', '" .$tenphuhuynh2 ."', '" .$dienthoaiphuhuynh1 ."', '" .$dienthoaiphuhuynh2 ."', '" .$dienthoaiphuhuynh3 ."', '" .$emailphuhuynh ."')";
					//echo '<p>' .$cmdText_Address .'</p>';
			
                    $cmdText_Students_Join_Address = "INSERT INTO `students_join_address`(`id`, `student_id`, `address_id`) VALUES ('" .$_join_address_id ."', '" .$_student_id ."', '" .$_address_id ."')";
					//echo '<p>' .$cmdText_Students_Join_Address .'</p>';
				
                    $cmdText_Student_Enrollment = "INSERT INTO `student_enrollment`(`id`, `syear`, `school_id`, `student_id`, `grade_id`, `start_date`, `next_school`, `calendar_id`) VALUES (" .$_student_enrollment_id .", '"  .$_syear ."', '" .$_school_id ."', '" .$_student_id ."', '" .$_grade_id ."', '" .$_start_date ."', '" .$_next_school ."', '" .$_calendar_id ."')";
					//echo '<p>' .$cmdText_Student_Enrollment .'</p>';
					
					$username = "";
					$password = "";
					$profile = "parent";
					$failed_login = "0";
					$profile_id = "3";
					
                    $cmtText_Staff = "INSERT INTO `staff`(`staff_id`, `current_school_id`, `first_name`, `last_name`, `username`, `password`, `phone`, `email`, `profile`, `failed_login`, `profile_id`) VALUES (" .$_staff_id .", '"  .$_school_id ."', '" .$tenphuhuynh1 ."', '" .$hophuhuynh1 ."', '" .$username ."', '" .$password ."', '" .$dienthoaiphuhuynh1 ."', '" .$emailphuhuynh ."', '" .$profile ."', '" .$failed_login ."', '" .$profile_id ."')";
					//echo '<p>' .$cmtText_Staff .'</p>';
					
                    $cmdText_Students_Join_Users = "INSERT INTO `students_join_users`(`student_id`, `staff_id`) VALUES ('" .$_student_id ."', '" .$_staff_id ."')";
					//echo '<p>' .$cmdText_Students_Join_Users .'</p>';
					
                    $cmdText_Staff_School_RelationShip = "INSERT INTO `staff_school_relationship`(`staff_id`, `school_id`, `syear`) VALUES ('" .$_staff_id ."', '" .$_school_id ."', '" .$_syear ."')";
					//echo '<p>' .$cmdText_Staff_School_RelationShip .'</p>';
					
                    insertDatabase($cmdText_Students, $cmdText_Address, $cmdText_Students_Join_Address, $cmdText_Student_Enrollment, $cmtText_Staff, $cmdText_Students_Join_Users, $cmdText_Staff_School_RelationShip);

				}
				}
				$i++;
			}
			}

			/**
			echo '<p>';
			//Chuyển toàn bộ thành chữ viết hoa
			//echo mb_convert_case($str, MB_CASE_UPPER, "UTF-8");
			echo '</p>';

			echo '<p>';
			//Chỉ chuyển chữ cái đầu tiên của mỗi từ thành
			//echo mb_convert_case($str, MB_CASE_TITLE, "UTF-8");
			echo '</p>';

			//Chuyển toàn bộ thành chữ thường
			echo '<p>';
			//echo mb_convert_case($str, MB_CASE_LOWER, "UTF-8");
			echo '</p>';
			**/
			
			echo '<p>' . 'Closed Database' .'</p>';
			/** Close Connect **/
		}
?>


</body>
</html>